package com.mxchip.livestarmobile.mobile.repository

import android.annotation.SuppressLint
import android.util.Log

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData

import com.mxchip.livestarmobile.mobile.util.RxBus.RxBus
import com.mxchip.livestarmobile.mobile.util.RxBus.RxSchedulersHelper
import com.mxchip.livestarmobile.mobile.constant.RxConstant

import io.reactivex.Observable

class SocketRepository {

    private val isConnect = MutableLiveData<Boolean>()
    private lateinit var isConnect_rx: Observable<Boolean>

    fun getIsConnect(): LiveData<Boolean> {
        return isConnect
    }

    @SuppressLint("CheckResult")
    fun init() {

        isConnect.value = false

        isConnect_rx = RxBus.get().register(RxConstant.CHANGE_NET_STATE, Boolean::class.java)
        isConnect_rx.compose(RxSchedulersHelper.io_main()).subscribe({ v -> isConnect.setValue(v) }, { error -> Log.e(TAG, "initRxBus isConnect_rx error") })
    }

    companion object {

        // private static SocketRepository sInstance;

        private val TAG = "SocketRepository"
    }


    /*public static SocketRepository getInstance() {
        if (sInstance == null) {
            synchronized (SocketRepository.class) {
                if (sInstance == null) {
                    // init();
                }
            }
        }
        return sInstance;
    }*/


}
